<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in goods_info.pics" :key="index">
				<view class="swiper-item">
					<image :src="item.pics_big" mode=""></image>
				</view>
			</swiper-item>
		</swiper>
		<!-- 商品信息区域 -->
		<view class="goods-info-box">
			<!-- 商品价格 -->
			<view class="price">￥{{goods_info.goods_price}}</view>
			<!-- 信息主体区域 -->
			<view class="goods-info-body">
				<!-- 商品名称 -->
				<view class="goods-name">{{goods_info.goods_name}}</view>
				<!-- 收藏 -->
				<view class="favi">
					<uni-icons type="star" size="18" color="gray"></uni-icons>
					<text>收藏</text>
				</view>
			</view>
			<!-- 运费 -->
			<view class="yf">快递：免运费</view>
		</view>
		<!-- 商品详情信息 -->
		<rich-text :nodes="goods_info.goods_introduce"></rich-text>
		<view class="goods_nav">
			<uni-goods-nav :fill="true" :options="options" :button-group="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>

	</view>

</template>

<script>
	import goodsAPI from '../../api/goodsAPI.js'
	export default {
		data() {
			return {
				query: {},
				// 商品详情对象
				goods_info: {},
				// 商品底部导航
				options: [ {
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#fff',
					infoColor: "red"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 5
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			}
		},
		methods: {
			async getGoodsDetail(goods_id) {
				const {
					data: res
				} = await goodsAPI.getGoodsDetail(goods_id)
				this.goods_info = res.message
				console.log('this.goods_info', this.goods_info);
			},
			onClick(e) {
				let mystr ='我爱我的祖国'
				let mystr2 = mystr.replace(/我/g,'你')
				console.log(mystr2);
				
				// 左侧按钮点击
				console.log('e=',e);

				if(e.index === 0){
					//跳转店铺
					uni.navigateTo({
						url: '/pages/shop/shop'
					})
				} else if(e.index === 1) {
					//跳转购物车
					uni.switchTab({
						url: '/pages/cart/cart'
					})
				} 
			},
			buttonClick(e) {
				// 右侧按钮点击
				console.log('e=',e);

				if(e.index === 0){
					//加入购物车
					console.log('加入购物车功能');
				} else if(e.index === 1) {
					//立即购买
					console.log('立即购买功能');
				} 
			}

		},
		onLoad(options) {
			console.log('options', options);
			this.query = options
			this.getGoodsDetail(options.goods_id)
		}

		// mounted() {
		// 	console.log('goodsId = ',this.$mp.query.goods_id);
		// 	this.query = this.$mp.query
		// }
	}
</script>

<style lang="scss">
	swiper {
		height: 750rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	// 商品信息区域的样式
	.goods-info-box {
		padding: 10px;
		padding-right: 0;

		.price {
			color: #c00000;
			font-size: 18px;
			margin: 10px 0;
		}

		.goods-info-body {
			display: flex;
			justify-content: space-between;

			.goods-name {
				font-size: 13px;
				padding-right: 10px;
			}

			// 收藏区域
			.favi {
				width: 120px;
				font-size: 12px;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				border-left: 1px solid #efefef;
				color: gray;
			}
		}

		// 运费
		.yf {
			margin: 10px 0;
			font-size: 12px;
			color: gray;
		}
	}

	.goods-detail-container {
		// 给页面外层的容器，添加 50px 的内padding，
		// 防止页面内容被底部的商品导航组件遮盖
		padding-bottom: 50px;
	}

	.goods_nav {
		// 为商品导航组件添加固定定位
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
	}
</style>